package api

import (
	"blog/app/resource/system"
	"blog/core"
	"blog/core/request"
	"blog/utils/tools/convert/file"
	"github.com/shirou/gopsutil/v3/host"
	"github.com/shirou/gopsutil/v3/mem"
)

type System struct {
}

// GetInfo , 获得系统信息
func (s System) GetInfo(req request.InterfaceRequest) {
	v, _ := mem.VirtualMemory()
	info, _ := host.Info()
	req.Response().Data(system.Info{
		Total:       file.New(int64(v.Total), "byte").MB(),
		Free:        file.New(int64(v.Free), "byte").MB(),
		UsedPercent: v.UsedPercent,
		OS:          info.OS,
	}).Success()
}

func (s System) PhotoOfTheDay(req request.InterfaceRequest) {
	req.Response().Data(map[string]interface{}{
		"url": core.Redis.GetString().Get("photo_of_the_day"),
	}).Success()
}
